package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.BusReciptInfo;
import com.ruoyi.system.domain.BusSupplierInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IBusSupplierInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 供应商信息Controller
 *
 * @author hst
 * @date 2021-11-24
 */
@RestController
@RequestMapping("/system/supplier")
public class BusSupplierInfoController extends BaseController
{
    @Autowired
    private IBusSupplierInfoService busSupplierInfoService;

    /**
     * 查询供应商信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusSupplierInfo busSupplierInfo)
    {
        startPage();
        List<BusSupplierInfo> list = busSupplierInfoService.selectBusSupplierInfoList(busSupplierInfo);
        return getDataTable(list);
    }
    /**
     * 导入数据
     */

//    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:supplier:import')")
//    @PostMapping("/importData")
//    public AjaxResult importData(BusSupplierInfo busSupplierInfo)
//    {
//        List<BusSupplierInfo> list = busSupplierInfoService.ImportBusSupplierInfoList(busSupplierInfo);
//        ExcelUtil<BusSupplierInfo> util = new ExcelUtil<BusSupplierInfo>(BusSupplierInfo.class);
//        return util.exportExcel(list, "供应商信息数据");
//
//    }
//
//    @GetMapping("/importTemplate")
//    public AjaxResult importTemplate()
//    {
//        ExcelUtil<BusSupplierInfo> util = new ExcelUtil<BusSupplierInfo>(BusSupplierInfo.class);
//        return util.importTemplateExcel("用户数据");
//    }

    /**
     * 导出供应商信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:export')")
    @Log(title = "供应商信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusSupplierInfo busSupplierInfo)
    {
        List<BusSupplierInfo> list = busSupplierInfoService.selectBusSupplierInfoList(busSupplierInfo);
        ExcelUtil<BusSupplierInfo> util = new ExcelUtil<BusSupplierInfo>(BusSupplierInfo.class);
        return util.exportExcel(list, "供应商信息数据");
    }

    /**
     * 获取供应商信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:query')")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Long supplierId)
    {
        return AjaxResult.success(busSupplierInfoService.selectBusSupplierInfoBySupplierId(supplierId));
    }

    /**
     * 新增供应商信息
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:add')")
    @Log(title = "供应商信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusSupplierInfo busSupplierInfo)
    {
        return toAjax(busSupplierInfoService.insertBusSupplierInfo(busSupplierInfo));
    }
    public AjaxResult add(@RequestBody BusReciptInfo busReciptInfo)
    {
        return toAjax((busSupplierInfoService.insertBusReciptInfo(busReciptInfo)));
    }
//    /**
//     * 新增发票信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:recipt:add')")
//    @Log(title = "发票信息", businessType = BusinessType.INSERT)
//    @PostMapping

    /**
     * 修改供应商信息
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:edit')")
    @Log(title = "供应商信息", businessType = BusinessType.UPDATE)
    @PutMapping

    public AjaxResult edit(@RequestBody BusSupplierInfo busSupplierInfo)
    {
        return toAjax(busSupplierInfoService.updateBusSupplierInfo(busSupplierInfo));
    }
    public AjaxResult edit(@RequestBody BusReciptInfo busReciptInfo)
    {
        return toAjax(busSupplierInfoService.updateBusReciptInfo(busReciptInfo));
    }

    /**
     * 删除供应商信息
     */
    @PreAuthorize("@ss.hasPermi('system:supplier:remove')")
    @Log(title = "供应商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds)
    {
        return toAjax(busSupplierInfoService.deleteBusSupplierInfoBySupplierIds(supplierIds));
    }
}
